<template>
  <el-form @submit.native.prevent="saveArticle" ref="form" :model="article" label-width="80px">
    <el-form-item label="文章标题">
      <el-input v-model="article.title"></el-input>
    </el-form-item>

    <el-form-item label="文章内容">
      <el-input type="textarea" v-model="article.body"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" native-type="submit">立即创建</el-button>
      <el-button>取消</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
export default {
  data() {
    return {
      article: {},
    };
  },
  methods: {
    saveArticle() {
      // 注意这边是post请求,post请求有两个参数,第一个是请求接口路径,第二个是请求体
      this.$http.post('/articles',this.article).then(res => {
        //饿了么新建成功提示
        this.$message({
          message: '文章新建成功',
          type: 'success'
        });
        this.$router.push('/articles/index')  //push表示跳到哪里
        // console.log(res.data)
      })
      // console.log(this.article);
    },
  },
};
</script>